﻿namespace Gmantis.Controls.Chart
{
    public class ChartPanelObjectCollection : System.Collections.ObjectModel.ObservableCollection<ChartPanelObject>
    {
        // Fields
        private ChartPanel _panel;

        // Methods
        internal ChartPanelObjectCollection(ChartPanel panel)
        {
            this._panel = panel;
        }

        protected override void ClearItems()
        {
            foreach (ChartPanelObject obj2 in this)
            {
                this._panel.DetachEvents(obj2, obj2.Action);
                obj2.Panel = null;
            }
            base.ClearItems();
            this._panel.BaseChildren.Clear();
        }

        protected override void InsertItem(int index, ChartPanelObject item)
        {
            base.InsertItem(index, item);
            this._panel.AttachEvents(item, item.Action);
            this._panel.BaseChildren.Insert(index, item);
            item.Panel = this._panel;
        }

        protected override void RemoveItem(int index)
        {
            ChartPanelObject obj2 = base[index];
            this._panel.DetachEvents(obj2, obj2.Action);
            base.RemoveItem(index);
            this._panel.BaseChildren.RemoveAt(index);
            obj2.Panel = null;
        }

        protected override void SetItem(int index, ChartPanelObject item)
        {
            this._panel.DetachEvents(base[index], base[index].Action);
            base[index].Panel = null;
            base.SetItem(index, item);
            this._panel.BaseChildren[index] = item;
            this._panel.AttachEvents(item, item.Action);
            item.Panel = this._panel;
        }
    }
}
